<?php
session_start();
header("Pragma:no-cache\r\n");
header("Cache-Control:no-cache\r\n");
header("Expires:0\r\n");
header("Content-Type: text/html; charset=uft-8");
define('INIT_XMALL',true);
define('INIT_ROOT','../');
ob_start();
require_once("conn.php");
require_once("../../config/config.php");

$fieldname = $_GET['fieldname'];
$strvalue = $_GET['strvalue'];

$sql = $_SESSION["xs_fieldcontent_".$fieldname];
$result = $db->query($sql);

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../sys/images/style.css" />
<style type="text/css">
<!--
body {
	margin:0px; border:0;
	font-size:12px; padding:0px; background:#ffffff;
}
-->
</style>
</head>
<body>
<form name="goform" id="goform" action="?save" method="post">
<!--搜索：
<input type="text" name="search" id="search" />
<input type="submit" name="button4" id="button4" value="搜索" />-->
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="45%"><select name="<?=$fieldname?>A" size="20" id="<?=$fieldname?>A" multiple="multiple" style="width:300px; height:350px;">
	<?php
	if (! empty($strvalue))
	{
		
		$arr = explode(',',$strvalue);
		foreach($arr as $vv)
		{
			if (!empty($vv)) {
			echo '<option value="'.$vv.'">'.$vv.'、【'.get_xxxname($sql,$vv).'】</option>';
			}
		} 
	}
	
	?>
    </select></td>
    <td width="10%" align="center">
    <br /><input type="button" name="button2" id="button2" value="&lt;&lt;" onclick="get_left()" />
    <br /><input type="button" name="button" id="button" value="&gt;&gt;"  onclick="get_right()"  />
    <br />
    </td>
    <td width="45%"><select name="<?=$fieldname?>B" size="20" id="<?=$fieldname?>B" multiple="multiple" style="width:450px; height:350px;">
	<?php
    while($row=mysql_fetch_array($result))
    {
    	echo '<option value="'.$row[0].'">'.$row[0].'、【'.str_len($row[1],56).'】</option>';
    }
    ?>
    </select></td>
  </tr>
</table>
</form>
<script>
function get_left()
{
	var SeleObj = document.getElementById("<?=$fieldname?>B");
	var tmpSelectValues="";
	var tmpSelectValues2="";
	var bbarr = new Array();
	//添加标记
	for (var i = 0;i<SeleObj.length; i++) {
		if (SeleObj.options[i].selected) {;
			tmpSelectValues = SeleObj.options[i].value;
			tmpSelectValues2= SeleObj.options[i].text;
			bbarr[i] = SeleObj.options[i].value;
			var varItem = new Option(tmpSelectValues2,tmpSelectValues);      
    		document.getElementById("<?=$fieldname?>A").options.add(varItem);
		}
	}
	//删除标记
	for (var i = 0;i<SeleObj.length; i++) {
		
		for(var j=0; j<bbarr.length;j++ )
		{
			if (bbarr[j]==SeleObj.options[i].value)
			{
			document.getElementById("<?=$fieldname?>B").options.remove(i);
			}
		}
	}
	//更新标记
	get_part();
}



function get_right()
{
	var SeleObj = document.getElementById("<?=$fieldname?>A");
	var tmpSelectValues="";
	var tmpSelectValues2="";
	var bbarr = new Array();
	//添加标记
	for (var i = 0;i<SeleObj.length; i++) {
		if (SeleObj.options[i].selected) {
			tmpSelectValues = SeleObj.options[i].value;
			tmpSelectValues2= SeleObj.options[i].text;
			bbarr[i] = SeleObj.options[i].value;
			var varItem = new Option(tmpSelectValues2,tmpSelectValues);      
    		document.getElementById("<?=$fieldname?>B").options.add(varItem);
		}
	}
	//删除标记
	for (var i = 0;i<SeleObj.length; i++) {
		
		for(var j=0; j<bbarr.length;j++ )
		{
			if (bbarr[j]==SeleObj.options[i].value)
			{
			document.getElementById("<?=$fieldname?>A").options.remove(i);
			}
		}
	}
	//更新标记
	get_part();
}


function get_part()
{
	var SeleObj = document.getElementById("<?=$fieldname?>A");
	var tmpSelectValues="";
	for (var i = 0;i<SeleObj.length; i++) {
		tmpSelectValues += SeleObj.options[i].value+',';
	}
	parent.document.getElementById("<?=$fieldname?>").value = tmpSelectValues;
}

</script>
</body>
</html>
<?php

function get_xxxname($sql,$id)
{
	global $db;
	$result = $db->query($sql);
	while($row=mysql_fetch_array($result))
    {
    	if ($row[0]==$id)
		{
			return str_len($row[1],56);
		}
    }
}

?>